package com.view
{
	import com.utils.Alert;
	import com.utils.Design;
	import com.utils.Drag;
	import com.utils.ITip;
	import com.utils.Lang;
	import com.utils.Tips;
	import com.utils.URI;
	import com.view.resourceLoader.ResourceLoader;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	
	public class ViewBase
	{
		private var _swfName:String;
		public static var clsList:Array = [];
		public function ViewBase(){
		}
		
		public function show():void{return}
		
		public function render():void{}
		
		public function close():void{}
		
		public function clear():void{}
		
		public function loadPanel(swfName:String):void{
			_swfName = swfName;
			if(!resourceLoader.hasTargetSWF(_swfName)){
				var path:String = Path.prefix + _swfName + Path.extension;
				resourceLoader.load(path,_swfName,render);
			}else{
				render();
			}
		}
		
		public function switchSelf():void{
			!inStage ? show() : clearTarget();
		}
		
		public function get inStage():Boolean{
			return resourceLoader.hasTargetSWF(_swfName);
		}
		
		public function clearTarget():void{
			resourceLoader.clearTargetSWF(_swfName);
			if(clsList[_swfName] && clsList[_swfName].parent){
				clsList[_swfName].parent.removeChild(clsList[_swfName])
				clsList[_swfName] = null;
			}
		}
		
		/**
		 * 从路径中截取swf名字 
		 * @param path
		 */		
		private function getKey(path:String):String{
			var tempList:Array = path.split('/');
			return String(tempList[tempList.length-1]).split('.')[0];
		}
		
		/**ResourceLoader单例*/		
		public function get resourceLoader():ResourceLoader{
			return ResourceLoader.getInstance();
		}
		
		/**Design单例*/		
		public function get design():Design{
			throw Error('ViewBase-->design(),此处使用时需要修改,加载方式已经改变!')
			return Design.instance();
		}
		
		/**Lang单例*/		
		public function get lang():Lang{
			return Lang.instance();
		}
		
		/**View单例*/	
		public function get view():View{
			return View.getInstance();
		}
		
		/**Tips单例*/		
		public function get tips():Tips{
			return Tips.instance();
		}
		
		/**ITip单例*/	
		public function get iTip():ITip{
			return ITip.instance();
		}
		
		/**Alert单例*/	
		public function get alert():Alert{
			return Alert.instance();
		}
		
		/**Drag单例*/	
		public function get drag():Drag{
			return Drag.instance();
		}
		
		/**URI单例*/	
		public function get uri():URI{
			return URI.instance();
		}
		
		public function addview(target:DisplayObject):void{
			Vision.addView(Vision.MAIN,target);
			clsList[_swfName] = target;
		}
	}
}

class Path{
	/**前缀*/	
	public static const prefix:String = 'assets/panels/';
	/**后缀*/	
	public static const extension:String = '.swf';
	
}
